import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import Components from 'unplugin-vue-components/vite'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
import path from 'node:path'
const localIconPath = path.join(process.cwd(), 'src/assets/icon')

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [
        IconsResolver({
          //prefix: "icon", // 自动引入的Icon组件统一前缀，默认为 i，设置false为不需要前缀
          // {prefix}-{collection}-{icon} 使用组件解析器时，您必须遵循名称转换才能正确推断图标。
          customCollections: ['local-icon'] // 如若 Icons 配置本地图标，这里也需要配置
        })
      ]
    }),
    Icons({
      autoInstall: true,
      customCollections: {
        'local-icon': FileSystemIconLoader(localIconPath, (svg) =>
          svg.replace(
            /^<svg\s/,
            '<svg width="1em" height="1em" class="dida-icon"'
          )
        )
      }
    })
  ]
})
